<template>
  <div class="detail">
    <detail-navbar></detail-navbar>
    <router-link tag="span" :to="'/'" class="back">
      <i class="iconfont icon-fanhui"></i>
    </router-link>
    <img :src="bannerImg" alt @click="handleClick">
    <v-fade>
      <detail-gallary slot="fade" :gallaryImgs="gallaryImgs" v-if="isGallary" @toggle="handleClick"></detail-gallary>
    </v-fade>
    <detail-list :categoryList="categoryList"></detail-list>
  </div>
</template>
<script>
import { HTTP } from "../../models/HTTP";
import { DetailModel } from "../../models/DetailModel";
import DetailGallary from "./components/gallary";
import DetailNavbar from "./components/navbar";
import DetailList from "./components/List";
import VFade from "./components/fade";

const http = new HTTP();
const detailModel = new DetailModel();
export default {
  name: "detail",
  data() {
    return {
      categoryList: [],
      bannerImg: "",
      gallaryImgs: [],
      isGallary: false
    };
  },
  components: {
    DetailGallary,
    DetailNavbar,
    DetailList,
    VFade
  },
  mounted() {
    var id = this.$route.params.id;
    detailModel.getDetail(id).then(res => {
      this.handleData(res);
    });
  },

  methods: {
    handleData(res) {
      var data = res.data.data;
      var { bannerImg, categoryList, gallaryImgs } = data;
      this.bannerImg = bannerImg;
      this.categoryList = categoryList;
      this.gallaryImgs = gallaryImgs;
    },
    handleClick() {
      var isGallary = this.isGallary;
      this.isGallary = !isGallary;
    }
  }
};
</script>
<style lang="scss" scoped>
.detail {
  height: 3000px;
}
img {
  width: 100%;
}
.item img {
  width: 25px;
}
.back {
  position: absolute;
  padding: 20px;
  i {
    font-size: 50px;
    color: #fff;
  }
}
</style>
